#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

###########################################
#pidof_count=`pidstat -p ALL |grep pidof |grep -v grep|wc |awk '{print $1}'`
#echo "$pidof_count"
#if (( $pidof_count > 2 ))
#then
#        echo "there are $pidof_count pidof process"
#        exit $CRITICAL
#fi
##########################################


gfsmount=''

if [ -f /etc/init.d/glusterd ];then
        gfsmount="besfs2"
elif [ -f /etc/init.d/zecloudd ];then
        gfsmount="ybjgfs"
else
        echo "glusterfs isnot installed!"
        exit 2

fi


for choice in $gfsmount                    ###
do
        case $choice in
        ybjgfs)

		D_zfs=`/etc/init.d/zecloudd status |awk '{print $2}'`
		T_zfs=`ps -ef|grep zecloudd |grep -v grep |grep -v log|awk '{print $3}'`

		#echo $D_zfs, $T_zfs
		if [ "$D_zfs" != "(pid" ]
		then
			echo "zecloud daemon is stopped or wrong"
			exit $CRITICAL
		fi
		if [ "T$T_zfs" == "T" ]
		then
			echo "zecloud main process doesn't exist"
			exit $CRITICAL
		fi
		echo "zecloud daemon is OK"
		exit $OK
		;;
	besfs2)
		D_zfs=`/etc/init.d/glusterd status |awk '{print $2}'`

                T_zfs=`ps -ef|grep glusterd |grep -v grep |grep -v log|awk '{print $3}'`

                #echo $D_zfs, $T_zfs

                if [ "$D_zfs" != "(pid" ]

                then

                        echo "glusterd daemon is stopped or wrong"

                        exit $CRITICAL

                fi
		if [ "T$T_zfs" == "T" ]
		then
			echo "glusterd main process doesn't exist"
			exit $CRITICAL
		fi
		echo "glusterd daemon is OK"
		exit $OK
	;;
	esac
done
